/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.common.utils;


import cn.hutool.core.util.ObjectUtil;
import org.springblade.common.cache.DictCache;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.core.tool.utils.WebUtil;
import org.springblade.modules.repair.vo.PlanCheckPartVo;
import org.springblade.modules.system.entity.Dict;
import org.springframework.lang.NonNull;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotEmpty;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 通用工具类
 *
 * @author Chill
 */
public class CommonUtil {

	/**
	 * 判断对象属性是否全 不为空
	 * @param obj
	 * @return
	 * @throws IllegalAccessException
	 */
	public static Boolean isALLFieldNotNull(Object obj, List<String> keys) throws IllegalAccessException {
		// 获取所有属性
		Field[] fs = obj.getClass().getDeclaredFields();
		boolean result = true;
		for (Field f : fs) {
			f.setAccessible(true);
			if(ObjectUtil.isNotEmpty(keys) && !keys.contains(f.getName())){
				if(f.get(obj) == null || "".equals(f.get(obj).toString())){
					result = false;
					break;
				}
			}
		}
		return result;
	}

	public static Boolean isALLFieldNotNull(Object obj) throws IllegalAccessException {
		// 获取所有属性
		Field[] fs = obj.getClass().getDeclaredFields();
		boolean result = true;
		for (Field f : fs) {
			f.setAccessible(true);
			if(f.get(obj) == null || "".equals(f.get(obj).toString())){
				result = false;
				break;
			}
		}
		return result;
	}

	/**
	 * @Author lsay
	 * @Description {
	 *   根据请求UA获取请求来源
	 * }
	 * @Date 9:26 2024/10/16
	 * @Param ua
	 * @return 1-IOS 2-Android 3-小程序
	 **/
	public static Integer getRequestFromTypeByUA(String ua) {
		if(ua.contains("MicroMessenger")){
			return 3;
		}
		if(ua.contains("Android") || ua.contains("okhttp")){
			return 2;
		}if(ua.contains("iPhone") || ua.contains("CFNetwork")){
			return 1;
		}
		return null;
	}

	public static void main(String[] args) throws IllegalAccessException {
		PlanCheckPartVo planCheckPartVo = new PlanCheckPartVo();
		planCheckPartVo.setId(1L);
		System.err.println(isALLFieldNotNull(planCheckPartVo,null));
	}

}
